package br.com.vti.sisp_sicrim.model.entity;

import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlTransient;

import br.com.crud4j.core.model.Model;
import br.com.crud4j.core.model.annotation.Constraint;
import br.com.crud4j.core.model.annotation.Constraints;
import br.com.vti.sisp_sicrim.model.entity.enums.Status;

/**
 *
 * @author ednardomatos
 */
@Entity
@Table(name = "t_perfil_usuario", catalog = "desenvolvimento", schema = "e_seguranca")
@Constraints({ @Constraint(name = "nome_perfil_uk", message = {"error.campo.unico", "campo.nome"}) })
@SequenceGenerator(name = "seq_perfil_usuario", sequenceName = "e_seguranca.seq_perfil_usuario", initialValue = 1, allocationSize = 1)
public class PerfilUsuario implements Model<Integer> {
    
    private static final long serialVersionUID = -1214538344602657154L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_perfil_usuario")
    @Basic(optional = false)
    private Integer id;
    
    @NotNull
    @Basic(optional = false)
    @Size(min = 1, max = 100)
    private String nome;
    
    @Column(columnDefinition="bpchar(1) default = 'A'")
    private Status status;
    
    @OneToMany(mappedBy = "perfil")
    private List<Usuario> usuarioList;

    public PerfilUsuario() {
    }

    public PerfilUsuario(Integer id) {
        this.id = id;
    }

    public PerfilUsuario(Integer id, String nome) {
        this.id = id;
        this.nome = nome;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    @XmlTransient
    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PerfilUsuario)) {
            return false;
        }
        PerfilUsuario other = (PerfilUsuario) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.vti.sisp_sicrim.model.entity.PerfilUsuario[ id=" + id + " ]";
    }

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
    
}
